<div class="grid-container-8-2">
	<div class="grid-cell-1 grid-cell-middle">
		<div class="section-heading">
			<div class="page-header">
				<span class="page-number">{{page.numbering}}</span>
				<span class="page-title">{{page.title}}</span>
			</div>
		</div>
	</div>
	<div class="grid-cell-2 grid-cell-right grid-cell-middle">
		<div class="section-heading no-print" id="page-toolbar-{{ page.id }}">
			<div class="section-toolbar">
				{{#if canEdit}}
					<i class="add-section dicon {{constants.Icon.Plus}}" {{action "onShowSectionWizard" page}}>
						{{#attach-tooltip showDelay=1000}}Insert section above{{/attach-tooltip}}
					</i>
					<div class="gap"/>
					<i class="dicon {{constants.Icon.Edit}}" {{action "onEdit"}} />
					<div class="gap"/>
				{{/if}}
				<i class="dicon {{constants.Icon.Settings}}">
					{{#attach-popover class="ember-attacher-popper" hideOn="clickout click" showOn="click" isShown=false}}
						<div class="menu">
							<a class="item" href="#" id="page-copy-link-{{page.id}}" {{action "onCopyLink"}}>Copy link</a>
							{{#if (or canEdit permissions.documentCopy permissions.documentMove permissions.documentTemplate)}}
								<div class="divider"></div>
							{{/if}}
							{{#if canEdit}}
								<a class="item" href="#" id={{concat "edit-page-button-" page.id}} {{action "onEdit"}}>Edit</a>
							{{/if}}
							{{#if permissions.documentCopy}}
								<a class="item" href="#" id={{concat "copy-page-button-" page.id}} {{action "onShowCopyModal"}}>Copy</a>
							{{/if}}
							{{#if permissions.documentMove}}
								<a class="item" href="#" id={{concat "move-page-button-" page.id}} {{action "onShowMoveModal"}}>Move</a>
							{{/if}}
							{{#if permissions.documentTemplate}}
								<a class="item" href="#" id={{concat "publish-page-button-" page.id}} {{action "onShowPublishModal"}}>Publish</a>
							{{/if}}
							{{#if permissions.documentDelete}}
								<div class="divider"></div>
								<a class="item red" href="#" id={{concat "delete-page-button-" page.id}} data-toggle="modal" data-target={{concat "#delete-page-modal-" page.id}} data-backdrop="static">Delete</a>
							{{/if}}
							{{#if (and canEdit state.actionablePage)}}
								<div class="divider"></div>
								{{#unless state.indentDisabled}}
									<a class="item" href="#" id={{concat "toc-indent-button-" page.id}} {{action "pageIndent"}}>Indent</a>
								{{/unless}}
								{{#unless state.outdentDisabled}}
									<a class="item" href="#" id={{concat "toc-outdent-button-" page.id}} {{action "pageOutdent"}}>Outdent</a>
								{{/unless}}
								{{#unless state.upDisabled}}
									<a class="item" href="#" id={{concat "toc-up-button-" page.id}} {{action "pageUp"}}>Move up</a>
								{{/unless}}
								{{#unless state.downDisabled}}
									<a class="item" href="#" id={{concat "toc-down-button-" page.id}} {{action "pageDown"}}>Move down</a>
								{{/unless}}
							{{/if}}
						</div>
					{{/attach-popover}}
				</i>
				<div class="gap"/>
				<i class="dicon {{constants.Icon.Expand}} {{unless expanded "expand"}}" {{action "onExpand"}}>
					{{#attach-tooltip showDelay=1000}}Show/hide{{/attach-tooltip}}
				</i>
			</div>
		</div>
	</div>
</div>

{{#if permissions.documentCopy}}
	<div id={{concat "copy-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog modal-50" role="document">
			<div class="modal-content">
				<div class="modal-header">Copy Destination</div>
				<div class="modal-body">
					<p>This section and all nested sections will be copied to the selected document.</p>
					<Ui::UiSpacer @size="100" />
					<div class="form-group">
						<label>Space</label>
						{{ui/ui-select content=folders optionValuePath="id" optionLabelPath="name" selection=targetSpace action=(action "onSelectSpace")}}
					</div>
					<div class="form-group">
						<label>Document</label>
						{{ui/ui-select content=targetDocs optionValuePath="id" optionLabelPath="name" selection=targetDoc action=(action "onSelectDoc")}}
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Green light=true label=constants.Label.Copy onClick=(action "onCopyPage")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}

{{#if permissions.documentMove}}
	<div id={{concat "move-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog modal-50" role="document">
			<div class="modal-content">
				<div class="modal-header">Move Destination</div>
				<div class="modal-body">
					<p>This section and all nested sections will be moved to the selected document.</p>
					<Ui::UiSpacer @size="100" />
					<div class="form-group">
						<label>Space</label>
						{{ui/ui-select content=folders optionValuePath="id" optionLabelPath="name" selection=targetSpace action=(action "onSelectSpace")}}
					</div>
					<div class="form-group">
						<label>Document</label>
						{{ui/ui-select content=targetDocs optionValuePath="id" optionLabelPath="name" selection=targetDoc action=(action "onSelectDoc")}}
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Green light=true label=constants.Label.Move onClick=(action "onMovePage")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}

{{#if permissions.documentDelete}}
	<div id= {{concat "delete-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">Delete Section</div>
				<div class="modal-body">
					<p>Are you sure you want to delete this section?</p>
					<div class="form-group">
						<div class="form-check">
							{{input type="checkbox" class="form-check-input" checked=deleteChildren  id=(concat "delete-page-check-" page.id)}}
							<label class="form-check-label" for= {{concat "delete-page-check-" page.id}}>
								Also delete child sections
							</label>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Red light=true label=constants.Label.Delete onClick=(action "onDeletePage")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}

{{#if permissions.documentTemplate}}
	<div id={{concat "publish-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">Publish Reusable Content Block</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="block-title-{{page.id}}">Name</label>
						{{input id=(concat "block-title-" page.id) type="text" class="form-control mousetrap" placeholder="Enter name" value=blockTitle}}
						<small class="form-text text-muted">Provide a short title for the reusable content block</small>
					</div>
					<div class="form-group">
						<label for="block-desc-{{page.id}}">Description</label>
						{{textarea id=(concat "block-desc-" page.id) rows="3" class="form-control mousetrap" placeholder="Enter description" value=blockExcerpt}}
						<small class="form-text text-muted">Short description to help others understand the reusable content block</small>
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Green light=true label=constants.Label.Publish onClick=(action "onSavePageAsBlock")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}
